const app = new Vue({
  el: "#app",
  data: {
    topLeft: [
      {
        title: "新闻",
        link: "https://news.baidu.com",
      },
      {
        title: "hao123",
        link: "https://hao123.com",
      },
      {
        title: "地图",
        link: "https://map.baidu.com",
      },
      {
        title: "直播",
        link: "https://live.baidu.com",
      },
      {
        title: "视频",
        link: "https://haokan.baidu.com/?sfrom=baidu-top",
      },
      {
        title: "贴吧",
        link: "https://tieba.baidu.com",
      },
      {
        title: "学术",
        link: "https://xueshu.baidu.com",
      },
      {
        title: "更多",
        link: "#",
      },
    ],
    topRight: [],
  },
  methods: {},
  computed: {},
});
var toSou = document.querySelector(".toSou");
var inSou = document.querySelector(".inSou");
var ta = document.querySelector(".ta");
var ul = document.querySelector(".taul");
var form = document.querySelector("#form");
var btn = document.querySelector(".btn");
var tr = document.querySelector(".top-right");
var lul = document.querySelector(".liuul");
var tq = document.querySelector(".tq");
var liu = document.querySelector(".liu");
toSou.addEventListener("click", function () {
  var input = inSou.value.trim();
  if (input) {
    open("https://www.baidu.com/s?wd=" + input, "_self");
  }
});
document.addEventListener("keyup", (e) => {
  if (e.keyCode == 13) {
    var input = inSou.value.trim();
    if (input) {
      open("https://www.baidu.com/s?wd=" + input, "_self");
    }
  }
});
document.addEventListener(
  "click",
  () => {
    inSou.style.borderBottomLeftRadius = "10px";
    inSou.style.borderBottomRightRadius = "10px";
    ta.style.display = "none";
  },
  true
);
inSou.addEventListener("keyup", ulList);
inSou.addEventListener("click", ulList);
ul.addEventListener(
  "click",
  function (e) {
    if (e.target.nodeName.toLowerCase() == "li") {
      inSou.value = e.target.innerHTML;
      setTimeout(() => {
        open("https://www.baidu.com/s?wd=" + inSou.value.trim(), "_self");
      }, 200);
    }
  },
  false
);
tq.addEventListener("mouseover", () => {
  liu.style.display = "block";
});
liu.addEventListener("mouseover", () => {
  liu.style.display = "block";
});
tq.addEventListener("mouseout", () => {
  liu.style.display = "none";
});
liu.addEventListener("mouseout", () => {
  liu.style.display = "none";
});
function ulList() {
  ta.style.display = "block";
  inSou.style.borderBottomLeftRadius = "0";
  inSou.style.borderBottomRightRadius = "0";
  var val = inSou.value;
  var script = document.createElement("script");
  script.src = `https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=31253,33849,33759,26350,33811&wd=${val}&csor=3&pwd=r%27r%27r&cb=weather`;
  document.body.appendChild(script);
  if (inSou.value.trim() == "") {
    ta.style.display = "none";
    inSou.style.borderBottomLeftRadius = "10px";
    inSou.style.borderBottomRightRadius = "10px";
    for (let i = 0; i < 10; i++) {
      ul.children[i].innerHTML = "";
    }
  }
}

function weather(data) {
  for (let i = 0; i < 10; i++) {
    ul.children[i].innerHTML = data["g"][i].q;
  }
}

function getweather(data) {
  tr.children[0].innerHTML = data["city"];
  tr.children[1].innerHTML = data["weather"][0]["temp"];
  for (let i = 0, len = lul.children.length; i < len; i++) {
    let date = data["weather"][i]["date"];
    let weather = data["weather"][i]["weather"];
    let wind = data["weather"][i]["wind"];
    let temp = data["weather"][i]["temp"];
    lul.children[i].innerHTML = `<p>${date}</p>
    <p>${temp}</p>
    <p>${weather}</p>
    <p>${wind}</p>`;
  }
  liu.children[0].innerHTML = `<p>${data["city"]}</p>
  <p>${data["date"]}</p>
  <p>更新时间：</p>
  <p>${data["update_time"]}</p>`;
  console.log(data);
}

window.onload = function () {
  var script = document.createElement("script");
  script.src = `https://api.asilu.com/weather/?city=${"江门"}&callback=getweather`;
  document.body.appendChild(script);
};
function ScreenWidth() {
  if (screen.width <= 800) {
    open(' https://chancoki.gitee.io/m.page','_self')
  }
  
}
ScreenWidth()